package question2;

import java.util.ArrayList;
import java.util.HashMap;

public class MapDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        String s="study well and make progress every day . study well and progress every day . study hard and make progress every day";
        String[] ss=s.split(" ");
        for (String s1 : ss) {
            list.add(s1);
        }
        HashMap<String, Integer> hm = new HashMap<>();
        for (String s1 : list) {
            if (!hm.containsKey(s1)) {
                hm.put(s1, 1);
            }else {
                hm.replace(s1,hm.get(s1)+1);
            }
        }
        System.out.println("单词:study出现了"+hm.get("study")+"次");
        System.out.println("单词:and出现了"+hm.get("study")+"次");
        System.out.println("单词:well出现了"+hm.get("well")+"次");
        System.out.println("单词:progress出现了"+hm.get("progress")+"次");
        System.out.println("单词:hard出现了"+hm.get("hard")+"次");
        System.out.println("单词:make出现了"+hm.get("make")+"次");
        System.out.println("单词:every出现了"+hm.get("every")+"次");
        System.out.println("单词:day出现了"+hm.get("day")+"次");
        System.out.println("单词:.出现了"+hm.get(".")+"次");
    }
}
